using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Web;
using System.Net;

namespace Rapier.Kodachi
{
    public partial class FeedbackWindow : Form
    {
        public FeedbackWindow()
        {
            InitializeComponent();
            cbFeedbackType.SelectedIndex = 0;
        }

        private void bSend_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            SendToBugzScout();
            MessageBox.Show("Thank you for helping us to improve Kodachi!", "Thank You", MessageBoxButtons.OK, MessageBoxIcon.None);
            Close();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //AcceptButton = bSend;
        }

        private void bCancel_Click(object sender, EventArgs e)
        {
            Close();
        }


        private void SendToBugzScout()
        {
            /*
             * Valid parameters:
             *      email
             *      description
             *      extra
             *      scoutUserName
             *      scoutProject
             *      scoutArea
             *      defaultMessage ? (message to send back to user automatically...we'll just set this in FogBugz instead)
             */
            Random random = new Random();
            string description = cbFeedbackType.Text + ":" + System.Windows.Forms.Application.ProductVersion + ":" + random.Next();
            string parameters = String.Format("description={0}&extra={1}&scoutUserName=Administrator&scoutProject=Inbox&scoutArea=Undecided", HttpUtility.UrlEncode(description), HttpUtility.UrlEncode(tbFeedback.Text));
            if (tbEmail.Text != String.Empty)
            {
                parameters += "&email=" + tbEmail.Text;
            }

            string response = Global.HttpPost("http://rapiersoftware.com/fogbugz/scoutSubmit.asp", parameters);
        }
    }
}